package org.toools.gwt.demo.jpa;

import java.util.Collection;
import java.util.Date;
import java.util.Vector;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import net.sf.gilead.pojo.java5.LightEntity;

/**
 *
 * @author stefan asseg
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "Account.getAll", query = "SELECT a FROM Account a"),
    @NamedQuery(name = "Account.getById", query = "SELECT a FROM Account a WHERE a.id = :id"),
    @NamedQuery(name = "Account.getByEmail", query = "SELECT a FROM Account a WHERE a.email = :email"),
    @NamedQuery(name = "Account.getBySupervisor", query = "SELECT a FROM Account a WHERE a.supervisor = :supervisor")
})
public class Account extends LightEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
    private String email;
    private String supervisor;
    private String password;
    @Temporal(TemporalType.DATE)
    private Date date_created;
    @Temporal(TemporalType.DATE)
    private Date date_access;
    @OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
    private Collection<Company> companies = new Vector<Company>();

    public Account() {
    }

    public Account(String email, String supervisor, String password) {
        this.email = email;
        this.supervisor = supervisor;
        this.password = password;
        this.date_created = new Date();
        this.date_access = new Date();
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSupervisor() {
        return supervisor;
    }

    public void setSupervisor(String supervisor) {
        this.supervisor = supervisor;
    }

    public Collection<Company> getCompanies() {
        return companies;
    }

    public void setCompanies(Collection<Company> companies) {
        this.companies = companies;
    }

    public void setDate_access(Date date_access) {
        this.date_access = date_access;
    }

    public void setDate_created(Date date_created) {
        this.date_created = date_created;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getDate_access() {
        return date_access;
    }

    public Date getDate_created() {
        return date_created;
    }

    public String getPassword() {
        return password;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Account)) {
            return false;
        }
        Account other = (Account) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Account [id = " + id + "] [email = " + email + "] [supervisor = " + supervisor + "]";
    }
}
